<template>
  <router-view />
</template>

<script setup>
import useSettingsStore from '@/store/modules/settings';
import { handleThemeStyle } from '@/utils/theme';
import { getIndexPlatformInfo } from '@/api/appv2/appv2.js';
const store = useSettingsStore();
const getInfo = async () => {
  const res = await getIndexPlatformInfo();
  store.setPlatformInfo(res);
  store.setTitle(res.data.title);
  store.HasItExpired(res.data.expiredate);
  setFavicon(res.data.favicon);
  store.setwWtermark(res.data.watermark);
  store.setH5addr(res.data.h5addr);
  store.setMenuIcon({
    bigImg: res.data.logo,
    smallImg: res.data.smalllogo,
    logo: res.data.logo,
  });
  store.setBeOverdue({
    qrUrl: res.data.qrUrl,
    mobile: res.data.mobile.kf_phone,
    pv: res.data.pv,
    registerNum: res.data.registerNum,
  });

  // 小程序、app、h5、pc 链接
  store.setEntranceUrl({
    xcx: res.data.wxapp,
    app: res.data.appdown,
    h5: res.data.h5addr,
    logoUrl: res.data.favicon,
    pc: res.data.gwaddr,
  });

  // 已经购买的应用id
  store.setApplicationInfo({
    expiredate_time: res.data.expiredate_time,
    appId: res.data.appId,
  });
};
getInfo();
const setFavicon = (newIconUrl) => {
  // 创建新的 link 标签
  var newLink = document.createElement('link');
  newLink.rel = 'icon';
  newLink.type = 'image/x-icon';
  newLink.href = newIconUrl;

  var oldLinks = document.querySelectorAll('link[rel="icon"]');
  for (var i = 0; i < oldLinks.length; i++) {
    oldLinks[i].parentNode.removeChild(oldLinks[i]);
  }

  // 将新创建的 link 插入到 head 中
  document.head.appendChild(newLink);
};
onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
  });
});
</script>
<style>
@import './assets/styles/mybase.css';
</style>
